package com.seecen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seecen.pojo.Product;
import com.seecen.service.ProductService;
import com.seecen.mapper.ProductMapper;
import com.seecen.utils.Result;
import com.seecen.utils.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author 桃子
* @description 针对表【product】的数据库操作Service实现
* @createDate 2025-07-21 14:26:52
*/
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product>
    implements ProductService{

    @Autowired
    private ProductMapper productMapper;

    //查询所有上架商品
    @Override
    public Result listAllProducts() {
        LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Product::getStatus, 0)        // 只查上架商品
                .eq(Product::getIsDeleted, 0);   // 未删除
        List<Product> list = list(wrapper);
        return Result.ok(list);
    }

    //根据id查询商品
    @Override
    public Result getProductById(Integer productId) {
        LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Product::getProductId, productId)
                .eq(Product::getIsDeleted, 0);   // 未删除
        Product product = getOne(wrapper);
        if (product == null) {
            return Result.build(null, ResultCodeEnum.PASSWORD_ERROR);
        }
        return Result.ok(product);
    }

    @Override
    public Result queryProDetailById(Integer productId) {
        LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Product::getProductId, productId)
                .eq(Product::getStatus, 0)        // 上架商品
                .eq(Product::getIsDeleted, 0);   // 未删除
        Product product = getOne(wrapper);
        if (product == null) {
            return Result.build(null,ResultCodeEnum.PASSWORD_ERROR);
        }
        return Result.ok(product);
    }



}




